/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef COMMON_H
#define COMMON_H

#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <semaphore.h>
#include <unistd.h>
#include <securec.h>
#include "discover.h"
#include "discovery_service.h"

#include "softbus_adapter_crypto.h"
#include "softbus_bus_center.h"
#include "softbus_utils.h"

#ifdef __cplusplus
extern "C" {
#endif

#define MAC_SIZE 6

#define MAX_FOUND_DEVICE_NUM 32

#define MAC_STR "%02x:%02x:%02x:%02x:%02x:%02x"
#define MAC_ADDR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]


typedef struct {
    uint32_t num;
    DeviceInfo dev[MAX_FOUND_DEVICE_NUM];
} DeviceList;

inline void WaitInputEnter(const char *info)
{
    printf("==>%s", info);
    fflush(stdout);
    fflush(stdin);
    (void)getchar();
}

inline int32_t GetInputNumber(const char *info)
{
    int32_t num;
    printf("==>%s", info);
    fflush(stdout);
    fflush(stdin);
    (void)scanf_s("%d", &num, sizeof(num));
    return num;
}

inline void GetInputString(const char *info, char *str, uint32_t size)
{
    printf("==>%s", info);
    fflush(stdout);
    fflush(stdin);
    while (fgets(str, size, stdin) == NULL);

    char* pos = strchr(str,'\n');
    if (pos != NULL) *pos = '\0';
    getchar();
    //scanf("%s[^\n]" , str, size);
}

inline int GenRandInt(int randMin, int randMax)
{
    srandom(time(NULL));
    return (randMin + random() % (randMax - randMin));
}

#ifdef __cplusplus
}
#endif
#endif